﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace VisualMove.Data
{
    public class QRCodeWrapper
    {
        private int m_nCodeHash;

        // Assume QRCode name is GUID_Name
        public QRCodeWrapper(StorageFolder oStorageFolder)
        {
            QRCode = oStorageFolder.Name;
            m_nCodeHash = int.Parse(QRCode);
            if (QRCode.LastIndexOf('_') != -1)
            {
                QRCodeLabel = QRCode.Substring(QRCode.LastIndexOf('_') + 1);
            }
            else
            {
                QRCodeLabel = "Unlabeled";
            }
        }

        // Assume QRCode name is GUID_Name
        public QRCodeWrapper(string sQRCode)
        {
            m_nCodeHash = sQRCode.GetHashCode();
            QRCode = m_nCodeHash.ToString();
            if (QRCode.LastIndexOf('_') != -1)
            {
                QRCodeLabel = QRCode.Substring(QRCode.LastIndexOf('_') + 1);
            }
            else
            {
                QRCodeLabel = "Unlabeled";
            }
        }

        public string QRCodeLabel
        {
            get;
            set;
        }

        public string QRCode
        {
            get;
            set;
        }

        public override bool Equals(object obj)
        {
            QRCodeWrapper oQRCodeWrapper = obj as QRCodeWrapper;
            if (oQRCodeWrapper == null)
                return false;

            return oQRCodeWrapper.QRCode == QRCode;
        }

        public override int GetHashCode()
        {
            return m_nCodeHash;
        }

        public static bool operator ==(QRCodeWrapper oQR1, QRCodeWrapper oQR2)
        {
            if ((object)oQR1 == null)
            {
                if ((object)oQR2 == null)
                    return true;
                return false;
            }

            return oQR1.Equals(oQR2);
        }

        public static bool operator !=(QRCodeWrapper oQR1, QRCodeWrapper oQR2)
        {
            return !(oQR1 == oQR2);
        }
    }
}